package com.ccp.dev.system.controller;

import com.ccp.dev.core.basic.internationalization.SysBaseController;
import com.ccp.dev.core.basic.consts.UrlConstants;
import com.ccp.dev.core.basic.web.query.QueryFilter;
import com.ccp.dev.core.basic.util.UUIDUtils;
import com.ccp.dev.core.util.StringUtil;
import com.ccp.dev.core.util.RequestUtil;
import com.ccp.dev.system.model.TestIframe;
import com.ccp.dev.system.service.TestIframeService;
import com.ccp.dev.core.basic.annotion.Action;
import java.util.Date;
import java.util.List;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.ModelMap;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;

/**
 * 测试frmae用 信息操作处理控制器
 * 
 * @author zw
 * @date 2019-07-26 14:38:50
 */
@Controller
@RequestMapping("/system/testIframe")
public class TestIframeController extends SysBaseController{
	@Resource
	private TestIframeService testIframeService;

    /**
     * 功能描述: 跳转到首页
     *
     * @return: java.lang.String
     * @auther: zw
     * @date: 2019-07-26 14:38:50
     */
    @RequestMapping(UrlConstants.VIEW_DISPATCH_PREFIX + UrlConstants.MODULE_FUNCTION_LIST)
    @Action(description="跳转到测试frmae用首页")
    public String list() {
        return "testIframe/list";
    }

    /**
     * 功能描述: 跳转到新增页面
     *
     * @return: java.lang.String
     * @auther: zw
     * @date: 2019-07-26 14:38:50
     */
    @RequestMapping(UrlConstants.VIEW_DISPATCH_PREFIX + UrlConstants.MODULE_FUNCTION_ADD_UPDATE)
    @Action(description="跳转到测试frmae用新增页面")
    public String add(HttpServletRequest request,ModelMap modelMap) {
        String id = RequestUtil.getString(request,"id");
        modelMap.put("id",id);
        return "testIframe/add";
    }

    /**
     * 功能描述:  数据保存通用方法
     *
     * @param: testIframe 保存的对象
     * @return: java.lang.Object
     * @auther: zw
     * @date: 2019-07-26 14:38:50
     */
    @RequestMapping(UrlConstants.MODULE_FUNCTION_SAVE)
    @ResponseBody
    @Action(description="保存测试frmae用数据")
    public Object save(@RequestBody TestIframe testIframe) {
        String id = testIframe.getId();
        int result;
        if (StringUtil.isEmpty(id)) {
            //新增操作
            //新增数据前生成随机Id
            testIframe.setId(UUIDUtils.getUUIDFor32());
            result = testIframeService.add(testIframe);
        } else {
            //修改操作
            result = testIframeService.update(testIframe);
        }
        return result > 0 ? getResultDataSuccess("save.success") : getResultDataError("save.failure");
    }

    /**
     * 功能描述: 根据主键ID删除数据的通用删除方法
     *
     * @param: id 参数名称必须是"id"
     * @return: java.lang.Object
     * @auther: zw
     * @date: 2019-07-26 14:38:50
     */
    @PostMapping(UrlConstants.MODULE_FUNCTION_DELETE)
    @ResponseBody
    @Action(description="根据主键ID删除测试frmae用数据")
    public Object delete(@RequestParam("id") String id) {
        if (StringUtil.isEmpty(id)) {
            return fail("delete.failure.message");
        }
        int result = testIframeService.delByIdArray(id.split(","));
        return result > 0 ? getResultDataSuccess("delete.success") : getResultDataError("delete.failure");
    }
    /**
     * 功能描述: 根据主键id获取一条数据的通用查询方法
     *
     * @param: id 参数对象必须是"id"
     * @return: java.lang.Object
     * @auther: zw
     * @date: 2019-07-26 14:38:50
     */
    @RequestMapping(UrlConstants.MODULE_FUNCTION_GET)
    @ResponseBody
    @Action(description="根据主键id查询测试frmae用的一条数据")
    public Object get(@RequestParam("id") String id) {
        TestIframe testIframe = testIframeService.getOneById(id);
        if (null == testIframe) {
            return getResultDataError("get.failure");
        }
        return getResultDataSuccess("get.success",testIframe);
    }

    /**
     * 功能描述: 附带检索条件的分页查询
     *
     * @param: [request] http请求
     * @return: java.lang.Object
     * @auther: zw
     * @date: 2019-07-26 14:38:50
     */
    @RequestMapping(UrlConstants.MODULE_FUNCTION_LIST)
    @ResponseBody
    @Action(description="附带检索条件的分页查询测试frmae用")
    public Object list(HttpServletRequest request) {
        QueryFilter queryFilter = new QueryFilter(request, true);
        //分页数据
        List<TestIframe> pageDatas = testIframeService.queryList(queryFilter);
        return success(pageDatas, queryFilter.getPageBean().getTotalCount());
    }
	
}
